<%@page import="java.sql.DriverManager"%>
<%@page import="java.util.ArrayList"%>
<%@page import="Configurations.MySQL"%>
<%@page import="java.sql.PreparedStatement"%>
<%@page import="java.sql.ResultSet"%>
<%@page import="java.sql.Connection"%>
<%
    Connection con = null;
    PreparedStatement ps = null;
    Class.forName(MySQL.DB_DRIVER);
    con = DriverManager.getConnection(MySQL.DB_URL, MySQL.DB_USER, MySQL.DB_PASS);
    String sql = "UPDATE " + MySQL.DB_LOGIN + " SET "
            + MySQL.DB_LOGIN_EMAIL + "=?,"
            + MySQL.DB_LOGIN_CNTRY + "=?,"
            + MySQL.DB_LOGIN_RSRCH + "=?,"
            + MySQL.DB_LOGIN_AVAILABLE + "=?"
            + " WHERE " + MySQL.DB_LOGIN_USERNAME + "=?";
    ps = con.prepareStatement(sql);
    String research = request.getParameter("research1") + ","
            + request.getParameter("research2") + ","
            + request.getParameter("research3") + ","
            + request.getParameter("research4") + ","
            + request.getParameter("research5") + ","
            + request.getParameter("research6") + ","
            + request.getParameter("research7") + ","
            + request.getParameter("research8") + ",";
    ps.setString(1, request.getParameter("email"));
    ps.setString(2, request.getParameter("country"));
    ps.setString(3, research);
    ps.setString(4, request.getParameter("available"));
    ps.setString(5, (String) session.getAttribute("username"));
    System.out.println(ps.toString());
    ps.execute();
    session.setAttribute("profileChange", "");

    con.close();
    ps.close();

    // Redirect if this page is being displayed by itself
    // Redirect back to index.jsp when changes are saved is complete
    if (request.getServletPath().equals("/saveProfile.jsp")) {
        response.sendRedirect("");
    }
%>